#include "CardGroup.h"

CardGroup::CardGroup(unsigned int newSize)
{
	size = newSize;
	cards = new Card*[size];
	for(unsigned int i = 0; i < size; i++)
		cards[i] = 0;
}

CardGroup::CardGroup(const CardGroup& rhs)
{
	size = rhs.size;

	if(cards)
		Clear();

	cards = new Card*[size];

	for(unsigned int i = 0; i < size; i++)
	{
		Card* currentCard = rhs.cards[i];

		if(currentCard)
			AddCard(*currentCard, i);
	}
}

CardGroup::~CardGroup()
{
	Clear();
}

void CardGroup::AddCard(Card& card, unsigned int index)
{
	if(cards[index])
		delete cards[index];
	cards[index] = new Card(card);
}

const Card& CardGroup::GetCard(unsigned int index) const
{
	if(!cards[index])
		throw "Does not contain a card";
	return (*cards[index]);
}

void CardGroup::RemoveCard(unsigned int index)
{
	if(index < size && cards[index])
	{
		delete cards[index];
		cards[index] = 0;
	}
}

void CardGroup::Clear()
{
	RemoveAllCard();
	delete[] cards;
	cards = 0;
}

void CardGroup::RemoveAllCard()
{
	for(int i = 0; i < size; i++)
	{
		delete cards[i];
		cards[i] = 0;
	}
}

unsigned int CardGroup::GetSize() const
{
	return size;
}

bool CardGroup::Empty() const
{
	bool empty = true;

	if(cards != 0)
		for(unsigned int i = 0; i < size; i++)
		{
			if(cards[i] != 0)
				empty = false;
		}

	return empty;
}

bool CardGroup::IsEmpty(unsigned int slot) const
{
	return cards[slot] == 0;
}
